﻿namespace EFS.RC.CommunicatorContext.Operators
{
	public partial class AgentControls : EFS.RC.CommunicatorContext.Operators.Controls
	{
		public AgentControls()
		{
			InitializeComponent();

			// ignore in design tool
			if (!System.ComponentModel.DesignerProperties.IsInDesignTool)
			{
				ShowInlineMessage(null);
				if (!EFS.RC.CommunicatorContext.Common.Config.Main.ShowQuestionnaire)
				{
					labelQuestionnaire.Visibility = System.Windows.Visibility.Collapsed;
					controlQuestionnaire.Visibility = System.Windows.Visibility.Collapsed;
				}
			}
		}

		#region Properties
		/// Property ButtonHold: Get
		protected override System.Windows.Controls.Button ButtonHold
		{
			get
			{
				return buttonHold;
			}
		}

		/// Property ButtonResume: Get
		protected override System.Windows.Controls.Button ButtonResume
		{
			get
			{
				return buttonResume;
			}
		}
		#endregion

		/// Load data
		public void LoadData(
			System.String telephone)
		{
			// phone
			if (EFS.Common.Verify.String(telephone))
			{
				labelCustomer.Content = telephone;
			}
		}

		private void OpenPhoneCall(System.String phone)
		{
			// crete url
			System.Text.StringBuilder sbUrl = new System.Text.StringBuilder();
			sbUrl.AppendFormat("http://10.0.7.2:8888/phonecall.aspx?phoneNr={0}",
				phone);

			// open
			System.Windows.Browser.HtmlPage.Window.Navigate(
				new System.Uri(sbUrl.ToString()),
				"__blank",
				"fullscreen=no,status=yes,toolbar=no,location=no,menubar=no,directories=no,resizable=yes,scrollbars=yes");
		}

		private void buttoCardDataProtection_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			HandleButtonClicked(sender, new ButtonsEventArgs(ButtonType.RecorderPause));
		}

		/// ShowInlineMessage
		public void ShowInlineMessage(
			System.String message,
			System.Boolean beep = false,
			System.Int32? beepCount = null,
			System.Boolean showPopupMessage = false)
		{
			// prepare
			message = EFS.Common.Functions.String.GetTrimmedString(message);

			// show/hide
			textBlockInlineMessage.Text = message;
			borderInlineMessage.Visibility = EFS.Common.Verify.String(message) ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed;

			// if no message, break
			if (borderInlineMessage.Visibility != System.Windows.Visibility.Visible)
			{
				return;
			}

			// beep?
			if (beep)
			{
				controlPlaySound.Play(
					EFS.RC.CommunicatorContext.Resources.Caching.GetByteData("sound_beep_24_mp3"),
					beepCount,
					showPopupMessage ? message : null);
			}
		}

		/// OnLoaded
		protected override void OnLoaded(object sender, System.Windows.RoutedEventArgs e)
		{
			// call base
			base.OnLoaded(sender, e);

			//OpenPhoneCall("9112");
		}
	}

}